//
//  AbloutUsViewController.m
//  CPU_Utility
//
//  Created by leonardo on 15/10/23.
//  Copyright © 2015年 leonardo. All rights reserved.
//

#import "AboutUsViewController.h"
#import <MessageUI/MessageUI.h>
#import <AFNetworking.h>
#import <SDImageCache.h>
#import <KVNProgress.h>
@interface AboutUsViewController ()<MFMailComposeViewControllerDelegate>

@end

@implementation AboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%f,%f,%f,%f",self.view.bounds.size.width,self.view.bounds.size.height,SCREEN_WIDTH,SCREEN_HEIGHT);
    // Do any additional setup after loading the view from its nib.
    
}
-(void)viewWillAppear:(BOOL)animated{
//    KVNProgressConfiguration *configuration = [[KVNProgressConfiguration alloc] init];
//    
//    configuration.statusColor = [UIColor whiteColor];
//    configuration.statusFont = [UIFont fontWithName:@"HelveticaNeue-Thin" size:15.0f];
//    configuration.circleStrokeForegroundColor = [UIColor whiteColor];
//    configuration.circleStrokeBackgroundColor = [UIColor colorWithWhite:1.0f alpha:0.3f];
//    configuration.circleFillBackgroundColor = [UIColor colorWithWhite:1.0f alpha:0.1f];
//    configuration.backgroundFillColor = [UIColor colorWithRed:0.173f green:0.263f blue:0.856f alpha:0.9f];
//    configuration.backgroundTintColor = [UIColor colorWithRed:0.173f green:0.263f blue:0.856f alpha:1.0f];
//    configuration.successColor = [UIColor whiteColor];
//    configuration.errorColor = [UIColor whiteColor];
//    //configuration.stopColor = [UIColor whiteColor];
//    configuration.circleSize = 0.0f;
//    configuration.lineWidth = 1.0f;
//    configuration.fullScreen = NO;
//    //configuration.showStop = YES;
//    //configuration.stopRelativeHeight = 0.4f;
//    
//    configuration.tapBlock = ^(KVNProgress *progressView) {
//        // Do something you want to do when the user tap on the HUD
//        // Does nothing by default
//    };
    
    
}

#pragma mark  评价
- (IBAction)btnRateApp:(UIButton *)sender {
    NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", APP_ID]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
#pragma mark 清楚缓存

- (IBAction)btnCleanCache:(UIButton *)sender {
    NSInteger sizeCache = [[SDImageCache sharedImageCache] getSize];
    
    NSArray * strUnits = @[@"B",@"KB",@"MB",@"GB"];
    NSInteger cout = 0;
    NSInteger value = sizeCache;
    while (value / 1024 > 0) {
        value = value / 1024;
        cout ++;
    }
    
    if (cout == 0 && value ==0) {
        [KVNProgress showErrorWithStatus:@"暂无缓存!"];
    }
    else{
        NSString * strSizeCache = [NSString stringWithFormat:@"已有缓存:%li%@",(long)value, strUnits[cout]];
       // NSLog(@"%@",NSHomeDirectory());
        UIAlertController * ac = [UIAlertController alertControllerWithTitle:strSizeCache message:@"确定清楚缓存?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * actionOK = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
                [KVNProgress showSuccessWithStatus:@"清除成功!"];
            }];
            

        }];
        
        UIAlertAction * actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        [ac addAction:actionOK];
        [ac addAction:actionCancel];
        [self presentViewController:ac animated:YES completion:nil];
    }
}
#pragma mark 建议
- (IBAction)btnAdvice:(UIButton *)sender {
    // 1. 先判断能否发送邮件
    if (![MFMailComposeViewController canSendMail]) {        // 提示用户设置邮箱
        return;
    }
    // 2. 实例化邮件控制器，准备发送邮件
    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    // 1) 主题 xxx的工作报告
    [controller setSubject:@"CPU Utility建议"];
    // 2) 收件人
    [controller setToRecipients:@[@"tanpengcd@gmail.com"]];
    // 3) cc 抄送
    // 4) bcc 密送(偷偷地告诉，打个小报告)
    // 5) 正文
    [controller setMessageBody:@"建议:<BR />1,<BR />2,<BR />3," isHTML:YES];
    // 6) 附件
//    UIImage *image = [UIImage imageNamed:@"头像1.png"];    NSData *imageData = UIImagePNGRepresentation(image);
//    // 1> 附件的二进制数据
//    // 2> MIMEType 使用什么应用程序打开附件
//    // 3> 收件人接收时看到的文件名称
//    // 可以添加多个附件
//    [controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"头像.png"];
    // 7) 设置代理
    controller.mailComposeDelegate = self;
    // 显示控制器
    [self presentViewController:controller animated:YES completion:nil];
    
}


//同样要记得发完邮件记得调用代理方法关闭窗口

#pragma mark - 邮件代理方法/** MFMailComposeResultCancelled,      取消 MFMailComposeResultSaved,          保存邮件 MFMailComposeResultSent,           已经发送 MFMailComposeResultFailed          发送失败 */

- (void)mailComposeController:(MFMailComposeViewController*)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error
{
    switch (result){
        case MFMailComposeResultCancelled:
            NSLog(@"Mail send canceled…");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved…");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail sent…");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail send errored: %@…", [error localizedDescription]);
            break;
        default:
            break;
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
